
#import "PageViewController.h"
#import "Answer.h"
#import <QuartzCore/QuartzCore.h>

#define scale @"<html><head><meta name=\"viewport\" content=\"width=device-width\"/><style>a,pre,code { white-space:pre-wrap; word-wrap:break-word; }</style></head><body>%@</body></html>"

@implementation PageViewController
@synthesize answers;
@synthesize pageIndex;

- (void)setPageIndex:(NSInteger)newPageIndex
{
	pageIndex = newPageIndex;
	
	if (pageIndex >= 0 && pageIndex < answers.count)
	{
        Answer *answer = [answers objectAtIndex:pageIndex];
		name.text = answer.name;
        date.text = answer.date;
        score.text = answer.score;
        webView.scrollView.bounces = NO;
        [webView loadHTMLString:[NSString stringWithFormat:scale,answer.text] baseURL:nil];
        if(answer.isAcceped){
            image.hidden = YES;
        }
			}
}
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;
{
    
    NSURL *loadURL = [[request URL]retain];
        if(![[loadURL scheme] isEqualToString: @"http"])
    {
        [loadURL release];
        return YES;
    }
    [loadURL release];
    return NO;
}

@end

